package com.css.fxfzfxqh.modules.taskMaps.service.impl;

import com.css.fxfzfxqh.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzfxqh.base.attachment.service.AttachmentInfoService;
import com.css.fxfzfxqh.modules.taskMaps.entity.TaskMaps;
import com.css.fxfzfxqh.modules.taskMaps.repository.TaskMapsRepository;
import com.css.fxfzfxqh.modules.taskMaps.service.TaskMapsService;
import com.css.fxfzfxqh.util.PlatformDateUtils;
import com.css.fxfzfxqh.util.PlatformSessionUtils;
import com.css.fxfzfxqh.util.UUIDGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: fxfzfxqh
 * @Author: lhl
 * @CreateDate: 2023/11/24 10:45
 */
@Service
public class TaskMapsServiceImpl implements TaskMapsService {
    @Resource
    TaskMapsRepository taskMapsRepository;
    @Resource
    AttachmentInfoService attachmentInfoService;

    @Override
    public List<TaskMaps> getByParam(TaskMaps entity) {
        List<TaskMaps> byParam = taskMapsRepository.getByParam(entity);
        for (TaskMaps taskMaps: byParam){
            AttachmentInfoEntity attach = attachmentInfoService.getAttach(taskMaps.getAttachId());
            taskMaps.setAttach(attach);
        }
        return byParam;
    }

    @Override
    public int save(TaskMaps entity) {
        entity.setId(UUIDGenerator.getUUID());
        entity.setDelFlag("0");
        entity.setCreateUser(PlatformSessionUtils.getUserId());
        entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        return taskMapsRepository.save(entity);
    }

    @Override
    public void deleteById(String id) {

        taskMapsRepository.deleteById(id,PlatformSessionUtils.getUserId(),PlatformDateUtils.getCurrentTimestamp());
        Map<String,String> map = new HashMap<>();
        map.put("attachId", id);
        attachmentInfoService.deleteFile(map);
    }
}
